<template>
	<view class="">
		<div class="banner">
			<image :src="banner" mode="widthFix"></image>
		</div>
		<div v-if="gjp">
			<u-skeleton :loading="true" :animate="true" rows="7"  rowsHeight="100"></u-skeleton>
		</div>
		
		<div class="zwxqPage" v-else>
			<div class="container">
				<div class="item">
					<h3>{{ zw.zwmc }}</h3>
					<div class="tags">
						<div>
							<u-tag :text="zw.year" type="error" plain plainFill size="mini"></u-tag>
						</div>
						<div>
							<u-tag :text="zw.zwxz" type="success" plain plainFill size="mini"></u-tag>
						</div>
						<div>
							<u-tag :text="zw.zy == '不限' ? '不限专业' : '限专业' " type="warning" plain plainFill size="mini"></u-tag>
						</div>
					</div>
					<ul>
						<li><span>招录人数</span> <i>{{ zw.zkrs }}</i></li>
						<li><span>职位代码</span> <i>{{ zw.zwdm }}</i></li>
						<li><span>招考单位</span> <i>{{ zw.bmmc }}</i></li>
					</ul>
				</div>
				
				<div class="tabBox">
					<ul class="tabTlt">
						<li @click="conIndex = 1" :class="conIndex == 1 ? 'cur' : ''">实时报名数据</li>
						<li @click="conIndex = 2" :class="conIndex == 2 ? 'cur' : ''">往年报名数据</li>
					</ul>
					<div class="tabContent">
						<div class="con" v-if="conIndex == 1">
							<div class="flexBox">
								<div class="bmrs_color">{{ zw.jfrs }}<span>当前缴费人数</span></div>
								<div class="bmrs_color">{{ zw.jfrs ? showJzb(zw.jfrs,zw.zkrs) : 0 }}<span>当前竞争比</span></div>
								<div class="bmrs_color">{{ ycData.ycbmrs }}<span>预测报名人数</span></div>
							</div>
						</div>
						<div class="con" v-if="conIndex == 2">
							<div class="fsBox" v-if="bmrsList.length >0">
								<div class="tableBox" v-for="(bmrs,index) in bmrsList" :key="index">
									<u-row>
										<u-col span="3">
											<div class="th">年份</div>
										</u-col>
										<u-col span="3">
											<div class="th">职位代码</div>
										</u-col>
										<u-col span="3">
											<div class="th">招考人数</div>
										</u-col>
										<u-col span="3">
											<div class="th">缴费人数</div>
										</u-col>
									</u-row>
									<u-row v-for="(b,j) in bmrs.list" :key="j">
										<u-col span="3">
											<div class="td">{{ bmrs.year }}</div>
										</u-col>
										<u-col span="3">
											<div class="td">{{ b.zwdm }}</div>
										</u-col>
										<u-col span="3">
											<div class="td">{{ b.zkrs }}</div>
										</u-col>
										<u-col span="3">
											<div class="td">{{ b.jfrs }}</div>
										</u-col>
									</u-row>
								</div>
							</div>
							<div class="fsBox" v-else>
								<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty>
							</div>
						</div>
						<p class="warningText">* 数据来源网络（雪恒教育-白雪面试整理发布）</p>
					</div>
				</div>
				<div class="tabBox">
					<ul class="tabTlt">
						<li @click="conIndex2 = 1" :class="conIndex2 == 1 ? 'cur' : ''">预测分数数据</li>
						<li @click="conIndex2 = 2" :class="conIndex2 == 2 ? 'cur' : ''">往年分数数据</li>
					</ul>
					<div class="tabContent">
						<div class="con" v-if="conIndex2 == 1">
							<div class="flexBox">
								<div class="bmrs_color" v-if="zw.jmfs">{{ zw.jmfs }}<span>实际进面分数</span></div>
								<div class="bmrs_color">{{ ycData.ycjmfs }}<span>预测进面分数</span></div>
								<div class="bmrs_color">{{ ycData.pjfs }}<span>平均进面分数</span></div>
							</div>
						</div>
						<div class="con" v-if="conIndex2 == 2">
							<div class="fsBox" v-if="bmrsList.length >0">
								<div class="tableBox" v-for="(bmrs,index) in bmrsList" :key="index">
									<u-row>
										<u-col span="2">
											<div class="th">年份</div>
										</u-col>
										<u-col span="2">
											<div class="th">职位代码</div>
										</u-col>
										<u-col span="3">
											<div class="th">进面分数</div>
										</u-col>
										<u-col span="3">
											<div class="th">面试分数</div>
										</u-col>
										<u-col span="2">
											<div class="th">总分数</div>
										</u-col>
									</u-row>
									<u-row v-for="(b,j) in bmrs.list" :key="j">
										<u-col span="2">
											<div class="td">{{ bmrs.year }}</div>
										</u-col>
										<u-col span="2">
											<div class="td">{{ b.zwdm }}</div>
										</u-col>
										<u-col span="3">
											<div class="td">{{ b.jmfs ? b.jmfs : '-' }}</div>
										</u-col>
										<u-col span="3">
											<div class="td">{{ b.msfs ? b.msfs : '-'  }}</div>
										</u-col>
										<u-col span="2">
											<div class="td">{{ b.zfs ? b.zfs : '-'  }}</div>
										</u-col>
									</u-row>
								</div>
							</div>
							<div class="fsBox" v-else>
								<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty>
							</div>
						</div>
						<p class="warningText">* 数据来源网络（雪恒教育-白雪面试整理发布）</p>
					</div>
				</div>
				<div class="item">
					<div class="btnBox" @click="toYc()">
						<image src="https://www.baixuemianshi.com/zhuanti/sk_stl/images/yc_btn.png" mode="widthFix"></image>
					</div>
				</div>
				<div class="item">
					<h3>职位信息</h3>
					<ul>
						<li><span>职位名称:</span>{{zw.zwmc}}</li>
						<li><span>职位代码:</span>{{zw.zwdm}}</li>
						<li><span>招考人数:</span>{{zw.zkrs}}</li>
						<li><span>职位性质:</span>{{zw.zwxz}}</li>
					</ul>
				</div>
				<div class="item">
					<h3>单位信息</h3>
					<ul>
						<li><span>地区:</span>{{zw.city}}</li>
						<li><span>所属系统:</span>{{zw.xt}}</li>
						<li><span>部门名称:</span>{{zw.bmmc}}</li>
						<li><span>部门代码:</span>{{zw.bmdm}}</li>
						<li><span>用人处（科）室:</span>{{zw.yrcs}}</li>
					</ul>
				</div>
				<div class="item">
					<h3>报考条件</h3>
					<ul>
						<li><span>招考对象:</span>{{zw.zkdx}}</li>
						<li><span>学历:</span>{{zw.xl}}</li>
						<li><span>专业:</span>{{zw.zy}}</li>
						<li><span>工作经历:</span>{{zw.gzjl}}</li>
						<li><span>政治面貌:</span>{{zw.zzmm}}</li>
						<li><span>岗位最低服务年限:</span>{{zw.fwnx}}</li>
					</ul>
				</div>
				<div class="item">
					<h3>其他信息</h3>
					<ul>
						<li><span>备注:</span>{{zw.bz}}</li>
					</ul>
				</div>
			</div>
			
		</div>
		<u-toast ref="uToast"></u-toast>
		<div class="loadBox" v-if="loading">
			<u-loading-icon size="36" mode="circle" :vertical="true" color="red" text="加载中..." textSize="20"></u-loading-icon>
		</div>
	</view>
</template>

<script>
	import {
		mapActions
	} from 'vuex';
	const db = wx.cloud.database();
	export default {
		data() {
			return {
				banner:"https://www.baixuemianshi.com/zhuanti/sk_stl/images/banner_zwxq.jpg?" + new Date(),
				gjp: true,
				colname: "",
				id:"",
				zw: "",
				bmrsList: [],
				loading: true,
				conIndex:1,
				conIndex2:1,
				ycData:{
					ycbmrs:0,
					ycjmfs:0,
					pjfs:0
				}
			};
		},
		onShow() {},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onPageScroll(e) {
			let that = this;
			that.scrollTop = e.scrollTop;
		},
		onLoad(options) {
			this.colname = options.colname
			this.id = options.id
			this.getZw()
		},
		computed: {
			
		},
		mounted() {
			
		},
		watch: {},
		created() {
			let that = this;
			
		},
		methods: {
			
			getZw(){
				let that = this
				db.collection(that.colname).doc(that.id).get({
					success: res => {
						that.zw = res.data
						that.loading = false
						that.gjp = false
						let nowYear = parseInt(that.zw.year) - 1
						that.filterBmrs(nowYear)
					}
				})
			},
			filterBmrs(year){
				let that = this
				db.collection(year + 'hlj_zwb').where({
					bmmc:that.zw.bmmc,
					zwmc:that.zwmc
				}).get({
					success:res => {
						if(res.data.length > 0){
							that.bmrsList.push({
								year: year,
								list:res.data
							})
						}
						if(year > 2021){
							let y = year - 1
							that.filterBmrs(y)
						}else{
							that.guessData()
						}
					}
				})
			},
			guessData(){
				let that = this
				let arr = []
				that.bmrsList.map(item => {
					item.list.map(item2 => {
						arr.push(item2)
					})
				})
				let zlrs = 0
				let bmrs = 0
				let jmfs = 0
				
				if(arr.length > 0){
					arr.map((item,index) =>{
						zlrs += parseInt(item.zkrs) ? parseInt(item.zkrs) : 0
						bmrs += parseInt(item.jfrs) ? parseInt(item.jfrs) : 0
						jmfs += parseFloat(item.jmfs) > 100 ? parseFloat(item.jmfs) / 2 : parseFloat(item.jmfs)
					})
				}else{
					
				}
				
				
				let ycrs = zlrs > 0 ? Math.ceil(that.zw.zkrs * (bmrs / zlrs)) : 0
				if(that.zw.zkdx == "不限身份人员"){
					ycrs += that.zw.zkrs > 5 ? that.zw.zkrs * 1 : that.zw.zkrs * 3
				}
				if(!that.zw.zzmm){
					ycrs += that.zw.zkrs > 5 ? that.zw.zkrs * 1 : that.zw.zkrs * 3
				}
				if(!that.zw.zy || that.zw.zy == '不限'){
					ycrs += that.zw.zkrs > 5 ? that.zw.zkrs * 1 : that.zw.zkrs * 3
				}
				that.ycData.ycbmrs = ycrs
				that.ycData.pjfs = jmfs ? Math.floor((jmfs / arr.length) * 100) / 100 : '-'
				
				if(jmfs){
					let wnjzb = bmrs / zlrs
					let nowjzb = that.showJzb(that.zw.jfrs,that.zw.zkrs)
					that.ycData.ycjmfs = nowjzb >= 1 ? Math.floor((that.ycData.pjfs + ((nowjzb - wnjzb) / 500 * 1.33)) * 100) / 100 : (that.ycData.pjfs + 1.33)
				}else{
					that.ycData.ycjmfs = 68.75
					if(that.zw.zkdx == "不限身份人员"){
						that.ycData.ycjmfs += 1.33
					}
					if(!that.zw.zzmm){
						that.ycData.ycjmfs += 1.33
					}
					if(!that.zw.zy || that.zw.zy == '不限'){
						that.ycData.ycjmfs += 1.33
					}
				}
				
				
			},
			showToast(type, info) {
				this.$refs.uToast.show({
					type: type,
					icon: false,
					title: '失败主题',
					message: info,
				})
			},
			showJzb(jfrs,zkrs){
				let jzb = jfrs / zkrs
				jzb % 1 === 0 ? jzb = jzb : jzb = jzb.toFixed(2)
				return jzb
			},
			toYc(){
				
			}
		},
		components: {}
	};
</script>

<style lang="scss">
	@import url(./index.css);
</style>
